package com.chutoutian.controller;

import com.chutoutian.common.Code;
import com.chutoutian.po.User;
import com.chutoutian.service.UserService;
import com.chutoutian.vo.ResponseMessage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping(value = "/v1")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping(value = "/user/{id}")
    public Object get(@PathVariable("id") String id) {
        return userService.get(id);
    }

    @PostMapping(value = "/user")
    public Object add(@RequestBody User user) {
        userService.add(user);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @PutMapping("/user")
    public Object update(@RequestBody User user) {
        userService.update(user);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @DeleteMapping("/user/{id}")
    public Object delete(@PathVariable("id") String id) {
        userService.delete(id);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }




}
